package com.southminority.ethnic.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 研究状态枚举
 * 
 * @author SouthMinority
 */
@Getter
@AllArgsConstructor
public enum ResearchStatusEnum {

    /**
     * 待开始
     */
    PENDING(1, "待开始", "pending"),

    /**
     * 进行中
     */
    IN_PROGRESS(2, "进行中", "in_progress"),

    /**
     * 暂停
     */
    PAUSED(3, "暂停", "paused"),

    /**
     * 已完成
     */
    COMPLETED(4, "已完成", "completed"),

    /**
     * 已取消
     */
    CANCELLED(5, "已取消", "cancelled"),

    /**
     * 审核中
     */
    UNDER_REVIEW(6, "审核中", "under_review"),

    /**
     * 已发布
     */
    PUBLISHED(7, "已发布", "published"),

    /**
     * 已归档
     */
    ARCHIVED(8, "已归档", "archived");

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 状态名称
     */
    private final String name;

    /**
     * 状态标识
     */
    private final String identifier;

    /**
     * 根据状态码获取枚举
     */
    public static ResearchStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ResearchStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 根据标识获取枚举
     */
    public static ResearchStatusEnum getByIdentifier(String identifier) {
        if (identifier == null || identifier.trim().isEmpty()) {
            return null;
        }
        for (ResearchStatusEnum status : values()) {
            if (status.getIdentifier().equalsIgnoreCase(identifier.trim())) {
                return status;
            }
        }
        return null;
    }

    /**
     * 判断是否为活跃状态
     */
    public static boolean isActive(Integer code) {
        return PENDING.getCode().equals(code) || 
               IN_PROGRESS.getCode().equals(code) || 
               UNDER_REVIEW.getCode().equals(code);
    }

    /**
     * 判断是否为完成状态
     */
    public static boolean isFinished(Integer code) {
        return COMPLETED.getCode().equals(code) || 
               PUBLISHED.getCode().equals(code) || 
               ARCHIVED.getCode().equals(code);
    }

    /**
     * 判断是否为暂停或取消状态
     */
    public static boolean isSuspended(Integer code) {
        return PAUSED.getCode().equals(code) || 
               CANCELLED.getCode().equals(code);
    }

    /**
     * 判断是否可以编辑
     */
    public static boolean isEditable(Integer code) {
        return PENDING.getCode().equals(code) || 
               IN_PROGRESS.getCode().equals(code) || 
               PAUSED.getCode().equals(code);
    }

    /**
     * 判断是否可以发布
     */
    public static boolean isPublishable(Integer code) {
        return COMPLETED.getCode().equals(code) || 
               UNDER_REVIEW.getCode().equals(code);
    }
}
